package ca.etsmtl.log730.projet2.connectors.clientserver.nodes;

import java.io.Serializable;

import org.apache.mina.core.session.IoSession;

import ca.etsmtl.log730.projet2.connectors.clientserver.setup.ConnectionData;
import ca.etsmtl.log730.projet2.connectors.clientserver.setup.LocalServerData;
import ca.etsmtl.log730.projet2.users.User;

public class NodeEntry implements Serializable, Comparable<NodeEntry> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4482412808936659129L;

	private User user = new User("");
	
	public NodeEntry() {
		setConnectionData(LocalServerData.getLocalServerMain());
	}
//	
//	public String getHostname() {
//		return hostname;
//	}
//	public void setHostname(String hostname) {
//		this.hostname = hostname;
//	}
//	public int getPort() {
//		return port;
//	}
//	public void setPort(int port) {
//		this.port = port;
//	}
//	private String hostname = "";
//	private int port = 1234;
	
	private ConnectionData connectionData = null;
	
	private IoSession session = null;

	public IoSession getSession() {
		return session;
	}
	public void setSession(IoSession session) {
		this.session = session;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	public int hashCode() {
		return connectionData.getPort();
	}
	
	public String toString() {
		String us;
		if(user == null) us = "????";
		else us = user.getName();
		return us.toString() + " @" + connectionData.getHostname() +"@" + connectionData.getPort();
	}
	@Override
	public int compareTo(NodeEntry ne) {
		return getConnectionData().compareTo(ne.getConnectionData());
	}
	
	public boolean equals(Object ne) {
		return toString().equals(ne.toString());
	}
	public ConnectionData getConnectionData() {
		return connectionData;
	}
	public void setConnectionData(ConnectionData connectionData) {
		this.connectionData = connectionData;
	}
	
}
